home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEX-UTIL
/
DVI_DVI1
/
dvilj
/
c
/
findfile
< prev
next >
Wrap
Text File
|
1996-02-20
|
5KB
|
193 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "fromosl.h"
/* #define FIND_DEBUG */
#define PATH_NOT_PRESENT 248 /* In case TeXFonts: isn't known */
#ifdef RISC_USE_OSL
#define TO_META_FILE emsize = sprintf
#define TO_META_DEST embuf
#define TO_META_FLUSH write_multi(embuf,1,emsize,metafile);
#else
#define TO_META_FILE fprintf
#define TO_META_DEST metafile
#define TO_META_FLUSH
#endif
#define METAFONTFILE_EXTENSION "lj-fonts"
#define METAFONTFILE_FIRSTLINE "wimpslot 960k"
#define MFMODE600 "ljiv"
#define MFMODE300 "hplaser"
void Fatal();
void *xosfile_set_type(char *, int);
extern char embuf[STRSIZE];
extern int emsize;
extern char filename[STRSIZE];
extern char MFFileName[STRSIZE];
extern FILEPTR metafile;
extern long4 RESOLUTION;
/* Finds font files */
bool findfile(char *path, char *name, long4 font_mag, char *full_name, bool mode, int number)
{
os_f fp;
long4 mag;
int spare;
os_error *ose;
fp = 0;
if (mode == _TRUE) {sprintf(full_name,"%s%s.tfm",path,name);}
else {mag = (10*font_mag+25)/50; sprintf(full_name,"%s%s.%dpk",path,name,mag);}
ose = xosfind_openin(0x43,full_name,path,&fp);
if (ose != NULL)
{
if (ose->errnum == PATH_NOT_PRESENT) {Fatal("Error #%d: %s\n",ose->errnum, ose->errmess);}
else {return(_FALSE);}
}
if (fp != FPNULL)
{
ose = xosargs_read_path(fp,full_name,STRSIZE,&spare);
if (ose != NULL) {return(_FALSE);} /* incredible but true: this happens! */
/* full_name[STRSIZE-spare] = 0;*/
xosfind_close(fp);
#ifdef FIND_DEBUG
printf("findfile: open <%s> OK.\n",full_name);
#endif
return(_TRUE);
}
else if (mode == _FALSE)
{
sprintf(full_name,"%s%s.%dpxl",path,name,mag);
ose = xosfind_openin(0x43,full_name,path,&fp);
if (ose != NULL)
{
if (ose->errnum == PATH_NOT_PRESENT) {Fatal("Error #%d: %s\n",ose->errnum, ose->errmess);}
else {return(_FALSE);}
}
if (fp != FPNULL)
{
ose = xosargs_read_path(fp,full_name,STRSIZE,&spare);
if (ose != NULL) {return(_FALSE);}
/*full_name[STRSIZE-spare] = 0;*/
xosfind_close(fp);
#ifdef FIND_DEBUG
printf("findfile: open <%s> OK.\n",full_name);
#endif
return(_TRUE);
}
}
#ifdef FIND_DEBUG
printf("findfile: open <%s> ERROR!\n",full_name);
#endif
return(_FALSE);
}
/* Mimics UNIX-Lib's access-function */
int access(char *name, int flag)
{
int obj_type,load_addr,exec_addr,size,actflag;
bits attr;
os_error *ose;
ose = xosfile_read(name,&obj_type,&load_addr,&exec_addr,&size,&attr);
if (ose != NULL) {return(-1);}
if (obj_type == 0) {return(-1);}
actflag = ((attr & 0x20) >> 4) || ((attr & 0x10) >> 2) ||
(attr & 2) || ((attr & 0) << 2);
if ((actflag & 2) != 0) {actflag |= 1;}
if (flag == actflag) {return(0);}
else {return(-1);}
}
/* (Creates a taskobey file and) appends commands to create missing fonts
to taskobey file. */
void MakeMetafontFile(char *path, char *name, int fontmag)
{
os_f fp;
int i,j,k;
os_error *ose;
char mfname[STRSIZE];
double mag;
char mode[16];
fp = 0;
sprintf(mfname,"%s%s.mf",path,name);
/* This shouldn't produce serious errors; those would have appeared
in the previous call to <findfile> */
if ((ose = xosfind_openin(0x43,mfname,path,&fp)) == NULL)
{
if (fp == 0) {printf("You're missing the metafont file for font <%s>!\n",name); return;}
if ((ose = xosargs_read_path(fp,mfname,STRSIZE,&i)) == NULL)
{
i = 0; j = 0;
while ((k = mfname[i++]) != '\0') {
if (k == '.') {j = i;}
}
mfname[j] = '\0';
if (metafile == FPNULL)
{
/* Strip "lj" of emitfile, append Metafontfile-extension instead */
i=0; j=0;
while ((k = filename[i]) != '\0') {
MFFileName[i++] = k; if (k == '.') {j = i;}
}
sprintf(&MFFileName[j],"%s",METAFONTFILE_EXTENSION);
if ((metafile = BOUTOPEN(MFFileName)) == FPNULL) {
printf("Error opening metafont command file <%s>!\n",MFFileName);
xosfind_close(fp); return;
}
xosfile_set_type(MFFileName,0xfd7); /* Task obey */
TO_META_FILE(TO_META_DEST,"%s\n",METAFONTFILE_FIRSTLINE); TO_META_FLUSH;
}
if (RESOLUTION == 600) {strcpy(mode,MFMODE600);}
else {strcpy(mode,MFMODE300);}
i = (10*fontmag + 25)/50; mag = ((double)i)/RESOLUTION;
TO_META_FILE(TO_META_DEST,"virmf &plain \\mode=%s; mag=%f; input %smf\n",mode,mag,mfname);
TO_META_FLUSH;
TO_META_FILE(TO_META_DEST,"gftopk %s%dgf %s%dpk\n",mfname,i,mfname,i); TO_META_FLUSH;
TO_META_FILE(TO_META_DEST,"wipe %s%dgf F~C~V\n",mfname,i); TO_META_FLUSH;
TO_META_FILE(TO_META_DEST,"wipe %slog F~C~V\n",mfname); TO_META_FLUSH;
}
xosfind_close(fp);
}
if (ose != NULL) {printf("Error (&%x): %s\n",ose->errnum,ose->errmess); return;}
}
#ifdef RISC_USE_OSL
/* Mimics fseek */
int os_seek(os_f fp, long int rel, int whence)
{
register int size, pos;
size = osargs_read_ext(fp);
switch(whence) {
case SEEK_SET: pos = rel; break;
case SEEK_CUR: pos = osargs_read_ptr(fp) + rel; break;
case SEEK_END: pos = size + rel; break;
default: pos = -1;
}
if ((pos < 0) || (pos > size)) {return(1);} /*
if (pos < 0) {osargs_set_ptr(fp,0); return(1);}
if (pos > size) {osargs_set_ptr(fp,size); return(1);}*/
osargs_set_ptr(fp,pos); return(0);
}
#endif